package com.ihr360.oneclick.controller;

import com.ihr360.commons.entity.AuthUserInfo;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.oneclick.dto.SalaryTypeSettingDto;
import com.ihr360.oneclick.service.SalaryTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/salary")
@Api(value = "/salary", description = "一键功能薪资接口", produces = ("application/json;charset=UTF-8"))
public class SalaryTypeController {

    @Autowired
    SalaryTypeService salaryTypeService;

    @PostMapping(value = "/addSalaryType")
    @ApiOperation(value = "/addSalaryType", httpMethod = "POST", notes = "新增薪资类型",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public ResultInfo addSalaryType(@RequestBody SalaryTypeSettingDto salaryType, AuthUserInfo authUserInfo) {
        salaryTypeService.addSalaryType(authUserInfo.getCompanyId(), salaryType);
        return new ResultInfo.Builder<String>().success();
    }

    @PostMapping(value = "/editSalaryType")
    @ApiOperation(value = "/editSalaryType", httpMethod = "POST", notes = "编辑薪资类型",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public ResultInfo editSalaryType(@RequestBody SalaryTypeSettingDto salaryType, AuthUserInfo authUserInfo) {
        salaryTypeService.editSalaryType(authUserInfo.getCompanyId(), salaryType);
        return new ResultInfo.Builder<String>().success();
    }

    @PostMapping(value = "/deleteSalaryType")
    @ApiOperation(value = "/deleteSalaryType", httpMethod = "POST", notes = "删除薪资类型",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public ResultInfo deleteSalaryType(@RequestBody List<String> idList, AuthUserInfo authUserInfo) {
        salaryTypeService.deleteSalaryType(authUserInfo.getCompanyId(), idList);
        return new ResultInfo.Builder<String>().success();
    }

    @GetMapping(value = "/findSalaryType")
    @ApiOperation(value = "/findSalaryType", httpMethod = "GET", notes = "查找薪资类型",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public ResultInfo findSalaryType(AuthUserInfo authUserInfo) {
        List<SalaryTypeSettingDto> salaryTypeSettingDtos = salaryTypeService.findSalaryType(authUserInfo.getCompanyId());
        return new ResultInfo.Builder<List<SalaryTypeSettingDto>>().success(salaryTypeSettingDtos);
    }
}
